package com.hdit.guimei.web;

import com.hdit.guimei.domain.Address;
import com.hdit.guimei.service.impl.AddressServiceImpl;
import com.hdit.guimei.util.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServlet;
import java.util.List;

/**
 * @author 张宝玉
 * @date 2021/1/18 17:13
 */
@Controller
public class AddressServlet extends HttpServlet{
    @Autowired
    public AddressServiceImpl addressService;
    /**
     *@methodName  findaddressbyid
     *@方法功能描述：通过id查找地址
     *@params  []
     *@return  java.lang.String
     *@author   张宝玉
     *@Date    2021/1/18 17:55
     */
    @RequestMapping("/findaddressbyid")
    public String findaddressbyid(int id){
        Address address = addressService.findaddressbyid(id);
        return null;
    }
    /*
     *@methodName  addaddress
     *@方法功能描述：添加收货地址
     *@params  [address]
     *
     *
     *@return  java.lang.String
     *@author   张宝玉
     *@Date    2021/1/18 18:06
     */
    @RequestMapping("/addaddress")
    public String addaddress(String address){
        Address address1=new Address();
        address1.setConsignee_address(address);
        int i = addressService.addaddress(address1);
        if (i==1){
            return null;
        }else {
            return null;
        }
    }
    //删除地址  修改地址的状态
    @RequestMapping("/deleaddress")
    @ResponseBody
    public String deleaddress(String aid){
        int i = addressService.deleaddress(aid);
        if (i==1){
            return "ok";
        }else{
            return "no";
        }
    }

    public  String updateaddress(int id,String address){
        int i = addressService.updateaddress(id, address);
        if (i==1){
            return "ok";
        }else{
            return  "no";
        }
    }
    @RequestMapping("/findAllAddress")
    @ResponseBody
    public ResponseData<List>  findAllAddress(){
        List<Address> addresses =  addressService.findAllAddress();
        ResponseData<List> res = new ResponseData<>();
        res.setCode(200);
        res.setMess("OK");
        res.setData(addresses);
        return res;
    }
}
